<?php
$r_url = "admin.php?file=gameunion";
#[判断权限]
if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["users"]&& !$QG_AP["games"])
{
	Error("对不起，您没有权限操作当前功能","admin.php?file=index");
}
if($sysact == "add" || $sysact == "modify")
{
	if($sysAct == "modify")
	{
		$id = intval($id);
		if(!$id)
		{
			Error("操作非法！","admin.php?file=gameunion&act=list");
		}
		$rs = $DB->qgGetOne("SELECT * FROM unions WHERE id='".$id."'");
	
	}
}
elseif($sysact == "viewok")
{
	$id = intval($id);
	$msg = $STR->safe($_POST);
	if($id)
	{
		$sql = "UPDATE unions SET u_id='".$msg["u_id"]."',country='".$msg["country"]."',uname='".$msg["uname"]."',u_ico='".$msg["u_ico"]."',uintro='".$msg["uintro"]."',umember='".$msg["umember"]."',umaxmember='".$msg["umaxmember"]."',ustate='".$msg["ustate"]."',udate='".strtotime($msg["udate"])."' WHERE id='".$id."'";
		$DB->qgQuery($sql);		
		$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
		Error("联盟信息更新成功",$r_url);
	}
	else
	{/*
		$sql = "SELECT username FROM ".$prefix."unions WHERE username='".$msg["username"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("城池名称 ".$msg["username"]." 已经存在",$r_url."&act=add");
		}
		$sql = "INSERT INTO ".$prefix."unions(c_id,u_id,c_name,c_population,c_officers,c_soldiers,c_area,c_area_x,c_area_y,total_hills,free_hills,total_woodlands,free_woodlands,total_flats,free_flats,total_barracks,free_barracks,total_house,free_house,unions_wall,c_img,c_size,c_total_size,c_land_type,c_type,create_date,ea_if) VALUES('','".$msg["u_id"]."','".$msg["c_name"]."','0','0','0','".$msg["c_area"]."','".$msg["c_area_x"]."','0','0','0','0','0','0','0','0','0','300','180','0','1','".$msg["c_size"]."','".$msg["c_total_size"]."','".$msg["c_land_type"]."','0','".time()."','1')";
		$DB->qgQuery($sql);*/
		Error("功能未开放！！！");
	}
}
elseif($sysact == "delete")
{
	$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$r_url);
	}
	$sql = "DELETE FROM ".$prefix."unions WHERE c_id='".$id."'";
	$DB->qgQuery($sql);
	Error("联盟信息删除成功",$r_url);
}
elseif($act == "list")
{
	$page_url = "admin.php?file=gameunion&act=list";
	$psize = 20;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);
	if($keywords)
	{
		if($stype == "u_id")
		{
			$condition .= " AND u_id LIKE '%".$keywords."%'";
		}
		elseif($stype == "id")
		{
			$condition .= " AND id LIKE '%".$keywords."%'";
		}
		elseif($stype == "uname")
		{
			$condition .= " AND uname LIKE '%".$keywords."%'";
		}
		
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}
	$count = $DB->qg_count("SELECT count(id) FROM ".$prefix."unions ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT *  FROM ".$prefix."unions ".$condition." ORDER BY id ASC LIMIT ".$offset.",".$psize);
}
Foot("gameunion.qg");
?>